package com.bwie.spike.controller;

import java.util.Arrays;
import java.util.Map;


import com.bwie.spike.entity.UserTo;
import com.bwie.spike.fegin.UserFegin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bwie.spike.entity.GoodsEntity;
import com.bwie.spike.service.GoodsService;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.R;



/**
 * 商品信息表
 *
 * @author lfw
 * @email sunlightcs@gmail.com
 * @date 2022-02-21 20:32:24
 */
@RestController
@RequestMapping("spike/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @Autowired
    UserFegin userFegin;





    /**
     * 商品详情
     */
    @RequestMapping("/item")
    public R item(@RequestParam("id")String id){
        GoodsEntity item = goodsService.getById(id);
        return R.ok().put("goods", item);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		GoodsEntity goods = goodsService.getById(id);

        return R.ok().put("goods", goods);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody GoodsEntity goods){
		goodsService.save(goods);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody GoodsEntity goods){
		goodsService.updateById(goods);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		goodsService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }



}
